******************************************************************************
** Name of file: replicate_rbindiaschools.do                                **
**       Author: Anita Dhillon                                              **
**      Purpose: Do file for replication of results found in the paper      **
**               "Representative bureaucracy in challenging environment:    **
**               Gender Representation, Education, and India			    **
** Date created: 15 July 2020                                               **
**    Data file: replicate_rbindiaschools.dta                               **
******************************************************************************

version 12.1
clear all
macro drop _all
set linesize 80

use replicate_rbindiaschools.dta, clear

sort pcg_p60g8
tsset schcd ac_year

// Table 1: Pooled OLS regression analysis with time fixed effects (and Appendix B2, C)
****Linear estimation (Model 1 in table 1 + Appendix table B2 + Appendix C graph)
reg pcg_p60g8 pc_femtch stratio tchhrs_upr wrkday_upr engmed hhi_caste infrastructure_index school_quality ruralsch govtsch pc_gradabove pc_tchwithprof schsexratio i.ac_year, r
estat sum
margins, at(pc_femtch=(0(10)100))
marginsplot, xtitle(Female teachers in school(%)) ytitle(Female students scoring 60%+ in grade 8 exam(%))

****Lagged DV estimation (Model 2 in table 1)
reg pcg_p60g8 pc_femtch l.pcg_p60g8 stratio tchhrs_upr wrkday_upr engmed hhi_caste infrastructure_index school_quality ruralsch govtsch pc_gradabove pc_tchwithprof schsexratio i.ac_year, r

**** Quadratic estimation (Model 3 in table 1 + Appendix C graph)
reg pcg_p60g8 c.pc_femtch##c.pc_femtch stratio tchhrs_upr wrkday_upr engmed hhi_caste infrastructure_index school_quality ruralsch govtsch pc_gradabove pc_tchwithprof schsexratio i.ac_year, r
margins, at(pc_femtch=(0(10)100))
marginsplot, xtitle(Female teachers in school(%)) ytitle(Female students scoring 60%+ in grade 8 exam(%)) 


// Table 2: Interactions with task difficulty measures
**** Interaction with instructional days (Model 1 in Table 2)
reg pcg_p60g8 c.pc_femtch stratio tchhrs_upr c.wrkday_upr engmed hhi_caste infrastructure_index school_quality ruralsch govtsch pc_gradabove pc_tchwithprof schsexratio c.wrkday_upr#c.pc_femtch i.ac_year, r
margins, dydx(pc_femtch) at(wrkday_upr=(30(30)250))
marginsplot, xtitle(No. of instructional days in a year) ytitle(Average Marginal effects of female teachers)

**** Interaction with teacher work hours (Model 2 in Table 2)
reg pcg_p60g8 c.pc_femtch stratio c.tchhrs_upr wrkday_upr engmed hhi_caste infrastructure_index school_quality ruralsch govtsch pc_gradabove pc_tchwithprof schsexratio c.tchhrs_upr#c.pc_femtch i.ac_year, r
margins, dydx(pc_femtch) at(tchhrs_upr=(2(2)12))
marginsplot, xtitle(No. of teacher working hours in a day) ytitle(Average Marginal effects of female teachers) 

**** Interaction with student teacher ratio (Model 3 in Table 2)
reg pcg_p60g8 c.pc_femtch c.stratio tchhrs_upr wrkday_upr engmed hhi_caste infrastructure_index school_quality ruralsch govtsch pc_gradabove pc_tchwithprof schsexratio c.stratio#c.pc_femtch i.ac_year, r
margins, dydx(pc_femtch) at(stratio=(5(15)150))
marginsplot, xtitle(Ratio of students to teachers) ytitle(Average Marginal effects of female teachers) 

**** Interaction with added task difficulty index (Model 4 in Table 2)
egen zwrkday_upr = std(wrkday_upr)
egen ztchhrs_upr = std(tchhrs_upr)
egen zstratio = std(stratio)
norm zwrkday_upr ztchhrs_upr zstratio, by(ac_year) method(mmx)
gen rev_mmx_zstratio = 1 - mmx_zstratio
gen wrkday_tchhrs_stratio = mmx_zwrkday_upr + mmx_ztchhrs_upr + rev_mmx_zstratio

reg pcg_p60g8 c.pc_femtch c.wrkday_tchhrs_stratio i.engmed c.hhi_caste c.infrastructure_index c.school_quality i.ruralsch i.govtsch c.pc_gradabove c.pc_tchwithprof c.schsexratio c.pc_femtch#c.wrkday_tchhrs_stratio i.ac_year, r
margins, dydx(pc_femtch) at(wrkday_tchhrs_stratio=(0.75(0.5)2.5))
marginsplot, xtitle(Added interaction) ytitle(Average Marginal effects of female teachers) 


// Table 3: Interactions with work environment measures
**** Interaction with rural school binary measure (Model 1 in Table 3)
reg pcg_p60g8 c.pc_femtch c.stratio c.tchhrs_upr c.wrkday_upr i.engmed c.hhi_caste c.infrastructure_index c.school_quality i.ruralsch i.govtsch c.pc_gradabove c.pc_tchwithprof c.schsexratio c.pc_femtch#i.ruralsch i.ac_year, r
margins, at(pc_femtch=(0(25)100) ruralsch=(0 1))
marginsplot, x(pc_femtch) recast(line) xtitle(Rural area school) ytitle(Average Marginal effects of female teachers)

**** Interaction with school infrastructure index (Model 2 in Table 3)
reg pcg_p60g8 c.pc_femtch c.stratio c.tchhrs_upr c.wrkday_upr i.engmed c.hhi_caste c.infrastructure_index c.school_quality i.ruralsch i.govtsch c.pc_gradabove c.pc_tchwithprof c.schsexratio c.pc_femtch#c.infrastructure_index i.ac_year, r
margins, dydx(pc_femtch) at(infrastructure_index=(-1.7(0.4)2))
marginsplot, xtitle(School Infrastructure Index) ytitle(Average Marginal effects of female teachers) 


**** Interaction with rural location and infrastructure index (Model 3 in Table 3)
drop if ruralsch==0
save rural_subset.dta, replace
use rural_subset.dta, clear
reg pcg_p60g8 c.pc_femtch c.stratio c.tchhrs_upr c.wrkday_upr i.engmed c.hhi_caste c.infrastructure_index c.school_quality i.govtsch c.pc_gradabove c.pc_tchwithprof c.schsexratio c.pc_femtch#c.infrastructure_index i.ac_year, r
margins , dydx(pc_femtch) at(infrastructure_index=(-1.7(0.4)2))
marginsplot, xtitle(School Infrastructure Index) ytitle(Average Marginal effects of female teachers) 

******Granger models (Models 1 and 2 in Appendix Table D2)
reg pcg_p60g8 L.pcg_p60g8 L.infrastructure_index pc_femtch stratio tchhrs_upr wrkday_upr engmed hhi_caste school_quality govtsch pc_gradabove pc_tchwithprof schsexratio i.ac_year, r
test L.infrastructure_index

reg infrastructure_index L.pcg_p60g8 L.infrastructure_index pc_femtch stratio tchhrs_upr wrkday_upr engmed hhi_caste school_quality ruralsch govtsch pc_gradabove pc_tchwithprof schsexratio i.ac_year, r
test L.pcg_p60g8


**** Interaction with urban location and infrastructure index (Model 4 in Table 3)
drop if ruralsch==1
save urban_subset.dta, replace
use urban_subset.dta, clear
reg pcg_p60g8 c.pc_femtch c.stratio c.tchhrs_upr c.wrkday_upr i.engmed c.hhi_caste c.infrastructure_index c.school_quality i.govtsch c.pc_gradabove c.pc_tchwithprof c.schsexratio c.pc_femtch#c.infrastructure_index i.ac_year, r
margins, dydx(pc_femtch) at(infrastructure_index=(-1.7(0.4)2))
marginsplot, xtitle(School Infrastructure Index) ytitle(Average Marginal effects of female teachers in urban schools) 

******Granger models (Models 3 and 4 in Appendix Table D2)
reg pcg_p60g8 L.pcg_p60g8 L.infrastructure_index pc_femtch stratio tchhrs_upr wrkday_upr engmed hhi_caste school_quality govtsch pc_gradabove pc_tchwithprof schsexratio i.ac_year, r
test L.infrastructure_index

reg infrastructure_index L.pcg_p60g8 L.infrastructure_index pc_femtch stratio tchhrs_upr wrkday_upr engmed hhi_caste school_quality ruralsch govtsch pc_gradabove pc_tchwithprof schsexratio i.ac_year, r
test L.pcg_p60g8


// Appendix A: Correlation between female students and female teachers
corr pc_femtch L.pc_femtch pc_totg pc_gr8g


// Appendix Table D1: IV estimation for task difficulty on female teachers (%) 
reg pc_femtch l.stratio l.tchhrs_upr l.wrkday_upr,r
testparm l.stratio l.tchhrs_upr l.wrkday_upr
predict ivresid, res
est store ivreg
reg pcg_p60g8 ivresid engmed hhi_caste infrastructure_index school_quality ruralsch govtsch pc_gradabove pc_tchwithprof schsexratio i.ac_year, r


exit
